package com.example.villagemanager.ui.activity;

import butterknife.BindView;

import android.os.Bundle;
import android.widget.TextView;

import com.example.villagemanager.R;
import com.example.villagemanager.config.Constant;
import com.example.villagemanager.model.bean.Person;
import com.example.villagemanager.model.entity.BaseResponse;
import com.example.villagemanager.model.event.Event;
import com.example.villagemanager.network.BaseObserver;
import com.example.villagemanager.network.RetrofitHelper;
import com.example.villagemanager.network.RxUtil;
import com.example.villagemanager.network.api.AppInfoApi;
import com.example.villagemanager.ui.base.BaseActivity;

public class PersonDetialActivity extends BaseActivity {


    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_sex)
    TextView tvSex;
    @BindView(R.id.tv_age)
    TextView tvAge;
//    @BindView(R.id.tv_name)
//    TextView tvName;
    private int personId=0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void initActivityData() {

    }

    @Override
    protected void initContentView() {
        mBundle=mIntent.getExtras();
        personId=mBundle.getInt(Constant.PERSON_ID,personId);
        httpFindPerson();

    }

    private void httpFindPerson() {
        RetrofitHelper.create(AppInfoApi.class)
                .findPerson(personId)
                .compose(RxUtil.observervableToMain())
                .as(RxUtil.bindLifecycle( this))
                .subscribe(new BaseObserver<Person>(getLoadingDialog()){
                    @Override
                    public void onSuccess(BaseResponse<Person> response) {
                        setViewData(response.getData());

                    }
                });
    }

    private void setViewData(Person data) {
        tvName.setText(data.getLabel());
        tvAge.setText(""+data.getAge());
        tvSex.setText(data.getGender()==0?"女":"男");
    }

    @Override
    protected int getContentView() {
        return R.layout.activity_person_detial;
    }

    @Override
    protected void onEventProcess(Event event) {

    }
}